package com.lcu.student.controller;

import com.lcu.Result.Result;
import com.lcu.student.entity.User;
import com.lcu.student.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/users")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 根据用户名判断密码是否正确密码
     * @param user
     * @return
     */
    @PostMapping("/login")
    public Result Login(@RequestBody User user){
        return userService.get(user.getUserName(), user.getUserPassword());
    }

    /**
     * 用户注册
     * @param user
     * @return
     */
    @PostMapping("/register")
    public Result Register(@RequestBody User user){
        return userService.addUser(user);
    }

    /**
     * 查询用户信息
     * @param user
     * @return
     */
    @PostMapping("/selectUser")
    public Result selectUser(@RequestBody User user){
        return userService.selectUser(user);
    }

    /**
     * 根据用户id修改密码
     * @param id
     * @param password
     * @return
     */
    @PutMapping("/updateById/{id}/{password}")
    public Result updateById(@PathVariable int id,@PathVariable String password){
        return userService.updateById(id,password);
    }

}
